package com.event.web.controller.system;

import com.event.common.annotation.Log;
import com.event.common.constant.UserConstants;
import com.event.common.core.controller.BaseController;
import com.event.common.core.domain.AjaxResult;
import com.event.common.core.page.TableDataInfo;
import com.event.common.enums.BusinessType;
import com.event.system.domain.SysEventRegion;
import com.event.system.domain.SysEventRegion;
import com.event.system.domain.SysEventRoster;
import com.event.system.service.ISysEventRegionService;
import com.event.system.service.ISysEventRegionService;
import com.event.system.service.ISysEventRosterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/eventRegion")
public class SysEventRegionController extends BaseController {

    private String prefix = "system/eventRegion";
    
    @Autowired
    private ISysEventRegionService sysEventRegionService;

    @Autowired
    private ISysEventRosterService sysEventRosterService;

    @RequiresPermissions("system:eventRegion:view")
    @GetMapping()
    public String eventRegion()
    {
        return prefix + "/eventRegion";
    }

    @RequiresPermissions("system:eventRegion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysEventRegion sysEventRegion)
    {
        startPage();
        List<SysEventRegion> list = sysEventRegionService.selectSysEventRegionList(sysEventRegion);
        return getDataTable(list);
    }

    /**
     * 新增展会区域
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("eventRoster", sysEventRosterService.selectSysEventRosterByAll());
        return prefix + "/add";
    }

    /**
     * 新增保存展会区域
     */
    @RequiresPermissions("system:eventRegion:add")
    @Log(title = "展会区域管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated SysEventRegion sysEventRegion)
    {
        return toAjax(sysEventRegionService.add(sysEventRegion));
    }

    /**
     * 修改展会区域
     */
    @RequiresPermissions("system:eventRegion:edit")
    @GetMapping("/edit/{regionId}")
    public String edit(@PathVariable("regionId") Long regionId, ModelMap mmap)
    {
        mmap.put("eventRoster", sysEventRosterService.selectSysEventRosterByAll());
        mmap.put("eventRegion", sysEventRegionService.selectSysEventRegionByRosterId(regionId));
        return prefix + "/edit";
    }

    /**
     * 修改保存展会区域
     */
    @RequiresPermissions("system:eventRegion:edit")
    @Log(title = "展会区域管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated SysEventRegion sysEventRegion)
    {
        return toAjax(sysEventRegionService.update(sysEventRegion));
    }

    /**
     * 删除展会区域
     */
    @RequiresPermissions("system:eventRegion:remove")
    @Log(title = "展会区域管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysEventRegionService.deleteSysEventRegionByRegionId(ids));
    }
}
